#include <iostream>
#include "uv.h"

using namespace std;

void timerCB(uv_timer_t *handle) {
    auto value = (long long) handle->data;
    cout << value << endl;
    if (value >= 126) {
        uv_timer_stop(handle);
        uv_ref((uv_handle_t*) handle);
        return;
    }
    handle->data = (void *) ++value;
}

void prepare_cb(uv_prepare_t *handle)
{
    printf("prepare handle callback\n");
}

int main() {

    uv_loop_t *loop = uv_default_loop();

    uv_prepare_t prepare;
    uv_prepare_init(loop, &prepare);
    uv_prepare_start(&prepare, prepare_cb);

    uv_timer_t timer;
    uv_timer_init(loop, &timer);

    timer.data = (void *) 123;
    uv_timer_start(&timer, timerCB, 0, 1000);

    uv_run(loop, UV_RUN_DEFAULT);

    return 0;
}
